<?php
/*
	Name: 			FormProcessor Class
	Author: 		Keith Alexander
	Description:	methods for validating and filtering form data, and for storing 
				    errors and messages related to that validation

*/
class FormFilter
{
	var $errors = array();
	var $messages = array();
	var $iri = '';
	var $redirect_location = false;
	var $post = array();
	
	function FormProcessor(&$post='', $iri = '', $redirect_location = false)
	{
		$this->post = $post;
		$this->iri = $iri; //now the developer can change the iri of the rdf with the class methods
		$this->redirect_location = $redirect_location; //and the redirect location once the form has been processed
		
	}
	
	/* Getters */
	
	function get_errors()
	{
		return $this->errors;
	}
	
	function get_messages()
	{
		return $this->messages;
	}
	
	/* Validators */
	
	function not_empty($val='', $parent_text='')
	{
		
		if(strlen($val) < 1 )
		{
			$this->errors[] = $parent_text.' is empty.';
			return false;
		}
		else
		{
			return $val;
		}
	}
	
	function is_valid_password($val='', $parent_text)
	{
		preg_match('/^[a-zA-Z0-9_-]+$/', $val, $m);
		return $m[0];
	}
	
	function is_valid_email($val='', $parent_text)
	{
		return $val;
		preg_match('/^[a-zA-Z0-9_-@\.]+$/', $val, $m);
	 	if($m[0]) return $m[0];
		else return false;
	}
	
	function is_valid_uri($val='', $parent_text)
	{
		return $val;
	}
	
	/* Filters */
	
	function generate_id($val=false)
	{
		if(!$val) 
		{
			$new_iri = str_replace('editor/','',$this->iri);
			$this->iri = $new_iri.time();
			$this->redirect_location = str_replace('/new','/',$this->iri);
			return time();
		}
		else
		{
			return $val;
		}
	}
	
	function set_iri($val='', $parent_text)
	{
		$this->iri = $val;
		return $val;
	}
	
	function set_redirect($val='', $parent_text)
	{
			$this->redirect_location = $val;
			return $val;
	}
	
	function sha1($val='', $parent_text='')
	{
		return sha1($val);
	}
	
	function is_unique($val='',$parent_text)
	{
		return $val;
	}
	
	function add_mailto($val='', $parent_text)
	{
		return 'mailto:'.$val;
	}
	
	
	
}
?>